package com.daifeng.gulimall.order.vo;


import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;

/**
 * 订单确认页需要的数据
 */
//  @Data
public class OrderConfirmVo {

    //  收货地址
    List<MemberAddressVo> addressVos;

    // 所有选中的购物项
    List<OrderItemVo> items;

    // 优惠券信息
    private Integer integration;

    //商品总件数
    private Integer count;

    // 订单总额
    BigDecimal totalPrice;

    // 应付总额
    BigDecimal payPrice;

    @Getter
    @Setter
    private String orderToken;


    public List<MemberAddressVo> getAddressVos() {
        return addressVos;
    }

    public void setAddressVos(List<MemberAddressVo> addressVos) {
        this.addressVos = addressVos;
    }

    public List<OrderItemVo> getItems() {
        return items;
    }

    public void setItems(List<OrderItemVo> items) {
        this.items = items;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }

    public Integer getCount() {
        Integer i = 0;
        if(items != null && items.size()>0){
            for (OrderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }

    public BigDecimal getTotalPrice() {
        BigDecimal amount = new BigDecimal("0");
        //1、计算购物项总价
        if (items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                if (item.getCheck()) {   //判断商品是否选中
                    BigDecimal totalPrice = item.getTotalPrice();
                    amount = amount.add(totalPrice);
                }
            }
        }

        return amount;
    }


    public BigDecimal getPayPrice() {
        //2、减去优惠总价
        return  getTotalPrice().subtract(new BigDecimal(integration));
    }

}
